NAME   ?= main
GOOS   ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)

BIN = ./$(NAME)
ifeq ($(GOOS),windows)
	BIN := $(BIN).exe
endif

.PHONY: build
build: tidy
	@GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(BIN) ./internal/admin/cmd/main.go

.PHONY: build-darwin
build-darwin:
	@make build GOOS=darwin GOARCH=amd64

.PHONY: build-linux
build-linux:
	@make build GOOS=linux GOARCH=amd64

.PHONY: build-windows
build-windows:
	@make build GOOS=windows GOARCH=amd64

.PHONY: test
test:
	@go test -gcflags=all=-l -covermode=count -coverprofile=./cover.out -coverpkg ./... ./...
	@go tool cover -func=./cover.out
	@go tool cover -html=./cover.out

.PHONY: fmt
fmt:
	@go fmt ./...
	@goimports -w -local `awk '$$1=="module" {print $$2}' ./go.mod` .

.PHONY: tidy
tidy:
	@go mod tidy; if [ -d vendor ]; then go mod vendor; fi

.PHONY: clean
clean:
	@rm main iris.yaml conf.yaml cover.out access.log

.PHONY: migrate
migrate:
	@Env=Develop go run ./scripts/create_table.go

.PHONY: dev
dev: build
	@Env=Develop go run ./internal/admin/cmd/main.go
